﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace MvcApplication1.Models
{
    public class EFDbContext : DbContext
    {
        public EFDbContext(string connection) : base(connection) { }

        public DbSet<Brand> Brands { get; set; }
        public DbSet<User> Users { get; set; }
    }

    [Table("brand")]   //without this attribute the name of the table to map from would be error name--'brands',why?
    public class Brand
    {
        public Int64 ID { get; set; }

        [Column("brandname", TypeName = "nvarchar")]
        public string BrandName { get; set; }

        [Column("registerTime", TypeName = "datetime")]
        public DateTime RegisterTime { get; set; }

        [Column("brandIntro", TypeName = "nvarchar")]
        public string BrandIntro { get; set; }
        [Column("logo", TypeName = "nvarchar")]
        public string Logo { get; set; }
        [Column("linkAddr", TypeName = "nvarchar")]
        public string LinkAddr { get; set; }
        public Int64 userID { get; set; }
        public Int64 itemCount { get; set; }
        public string BrandTitle { get;set; }
        public ICollection<BrandKeyword> BrandKeywords { get; set; }
    }

    [Table("userWithRole")]
    public class User
    {
        private string rolestr;
        public Int64 ID { get; set; }
        public string username { get; set; }
        public string password { get; set; }
        public DateTime lastlogin { get; set; }
        public bool isapproved { get; set; }
        public DateTime creationdate { get; set; }
        public string email { get; set; }
        public string role { get { return rolestr.Trim(); } set { rolestr = value; } }
    }

    [Table("userrole")]
    public class Role
    {
        public int ID { get; set; }
        public string username { get; set; }
        public string role { get; set; }
    }

    [Table("brandKeyword")]
    public class BrandKeyword
    {
        public Int64 ID { get; set; }
        public Int64 brandID { get; set; }
        public Int16 keywordSN { get; set; }
        public string keyword { get; set; }
    }
}